#ifndef UWindowThemerH
	#define UWindowThemerH
	#include "stdafx.h"
	#include "UIniFile/UIniFile.h"
	#include "UTextureManager.h"
	#include "UGLFont.h"

	class TControlContainer;
	class TDockable;
	class TThemedButton;

	enum WT_MOUSEHIT_RESULT { WT_MOUSEHIT_OUTSIDE_BORDER, WT_MOUSEHIT_INSIDE_BORDER, WT_MOUSEHIT_MOVEABLE,
												WT_MOUSEHIT_RESIZE_TOP_LEFT    , WT_MOUSEHIT_RESIZE_TOP   , WT_MOUSEHIT_RESIZE_TOP_RIGHT,
												WT_MOUSEHIT_RESIZE_LEFT        , WT_MOUSEHIT_RESIZE_RIGHT ,
												WT_MOUSEHIT_RESIZE_BOTTOM_LEFT , WT_MOUSEHIT_RESIZE_BOTTOM, WT_MOUSEHIT_RESIZE_BOTTOM_RIGHT,
												WT_MOUSEHIT_BUTTON_CLOSE, WT_MOUSEHIT_BUTTON_MINIMIZE, WT_MOUSEHIT_BUTTON_MAXIMIZE,
												};

	class TThemeElement {
		private:
			bool flipx;
			bool flipy;
			GLuint texture;
			int texturewidth;
			int textureheight;
		public:
			TThemeElement();
			TThemeElement(TThemeElement &te);
			TThemeElement(GLuint tex, int texturewidth, int textureheight, bool fx, bool fy);
			~TThemeElement();
			bool getFlipx();
			bool getFlipy();
			GLuint getTexture();
			int getTextureWidth();
			int getTextureHeight();
			void draw(GLfloat width, GLfloat height);
	};

	class TButtonThemeElement:public TThemeElement {
		private:
			GLfloat width;
			GLfloat height;
			GLfloat posrelativex;
			GLfloat posrelativey;
			GLfloat posabsolutex;
			GLfloat posabsolutey;
			std::vector<TThemeElement* > *buttons;
		public:
			enum {
				active_normal,
				active_highlight,
				active_clicked,
				inactive_normal,
				inactive_highlight,
				inactive_clicked
			};
			TButtonThemeElement(vector<TThemeElement *> *btns, GLfloat w, GLfloat h, GLfloat prx, GLfloat pry, GLfloat pax, GLfloat pay);
			~TButtonThemeElement();
			void draw(uint32 state, GLfloat w, GLfloat h);
			bool hitTest(int windowwidth, int windowheight, int x, int y);
	};

	class TBorderTheme {
		private:
			std::vector<TThemeElement* > *telem;
			GLfloat borderWidthLeft;
			GLfloat borderWidthRight;
			GLfloat borderWidthTop;
			GLfloat borderWidthBottom;
		public:
			enum btnStates	{	focused_normal, focused_highlight,
												focused_clicked,
												unfocused_normal, unfocused_highlight,
												unfocused_clicked,
											};

			uint8 titlecolor[3];
			TBorderTheme(std::vector<TThemeElement* > *telems, GLfloat borderWidthLeft, GLfloat borderWidthRight, GLfloat borderWidthTop, GLfloat borderWidthBottom);
			~TBorderTheme();
			void draw(const TDockable *window, bool hasFocus,int mouseX, int mouseY );
			WT_MOUSEHIT_RESULT mouseHit(const TDockable *window,const int &x,const int &y);
			GLfloat BorderTop(){return borderWidthTop;};
	};


// 	class TDockable;

	class TWindowThemer {
		private:
			string tfname;
			string tfpath;
			TThemeElement* GetThemeElement(string bname, TIniFile& inifile, TTextureManager& tm, std::string path, string section);
			TThemedButton* GetButtonThemeElement(string bname, TIniFile& inifile, TTextureManager &tm, string path  );
			bool load(std::string themename);
			void processLine(std::string line);
// 			GLuint textures[numberOfTextureNames];
			TGLFontRef GLFont;
			TBorderTheme *borderTheme;
		public:
			enum texturename {	top_left=0, top, top_right,
													left, right, bottom_left,
													bottom, bottom_right,
													button_close, button_minimize, button_maximize,
													numberOfTextureNames
			};
			TWindowThemer();
			~TWindowThemer();
			void draw(TDockable *window, bool hasFocus, int mouseX, int mouseY);
			WT_MOUSEHIT_RESULT mouseHit(const TDockable *window, const int &x, const int &y);
			TBorderTheme* BorderTheme() {return borderTheme;};

			void UpdateControls(TControlContainer* controls, TRectangle rect);
			void SetupControls(TDockable* dock);

	};

extern TWindowThemer* wt;

#endif //UWindowThemerH

